function shouldInterceptUrl(url) {
  // 自定义函数，根据你的规则判断是否需要拦截某个URL
  //console.log("url: "+url);
  return url.includes('scroll');
}

/**
// 使用webRequest API拦截AJAX请求
browser.webRequest.onHeadersReceived.addListener(
  (details) => {
    if (details.type === 'xmlhttprequest' && shouldInterceptUrl(details.url)) {
      console.log("Intercepted AJAX Response Headers:", details.responseHeaders);
      // 注意：这里仅能获取响应头，获取响应体需重新发起请求
    }
    return {};
  },
  { urls: ["<all_urls>"] },
  ["blocking", "responseHeaders"]
);
*/

console.log("init plutin: --------->");
browser.webRequest.onCompleted.addListener(
  (details) => {
    if (details.type === 'xmlhttprequest' && shouldInterceptUrl(details.url)) {
	  console.log("moonshot: "+details.url);
	  console.log("text: "+details);
	  /**
      // 重新发起请求以获取响应体
      fetch(details.url, {
        method: details.method,
        headers: details.requestHeaders,
        credentials: 'include',
        body: details.requestBody?.raw[0]?.bytes ?? undefined,
      })
      .then(response => response.text())
      .then(text => {
        console.log("Full AJAX Response Body:", text);
      })
      .catch(error => console.error("Error fetching AJAX response body:", error));
	  */
    }
  },
  { urls: ["<all_urls>"] },
  []
);

/**
// 使用webNavigation API拦截普通请求，特别是表单提交
browser.webNavigation.onCompleted.addListener(async (details) => {
  if (details.transitionType === browser.webNavigation.TRANSITION_FORM_SUBMIT && shouldInterceptUrl(details.url)) {
    console.log("Intercepted Regular Request:", details.url);
    // 这里可以添加逻辑来处理普通请求的响应，但直接获取响应内容较为复杂，
    // 因为webNavigation API不直接提供响应内容。可能需要在页面注入脚本或使用其他方法。
  }
}, { urls: ["<all_urls>"] });
*/